package com.deyuanyun.pic.ctrl.validatefun;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.validator.vinterface.ValidateInterface;
import com.deyuanyun.pic.ctrl.domain.EqptCppowerr;
import com.deyuanyun.pic.ctrl.domain.EqptCptestStation;
import com.deyuanyun.pic.ctrl.service.CpTestStationExpandService;
import com.deyuanyun.pic.ctrl.service.EQPTBaseService;
import com.deyuanyun.pic.ctrl.service.ImportService;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * 模块描述
 *
 * @author scalpel.王敏
 * @version [v1.0] 创建时间（2016/9/26）
 * @see // 引用的类
 * Method List:
 * 1.----------------
 * 2.----------------
 * History:
 */
public class MonitorPointValidata implements ValidateInterface {


    @Override
    public <T, E, C> boolean apply(T t, E e, C c) throws NoSuchFieldException {
        Field f=(Field) e;
        Object obj = c;
        String val= (String) t;
        try {
            String monitorPointType = BeanUtils.getSimpleProperty(c,"monitorPointType");
//

            BeanUtils.setProperty(c,"monitorPointName",val);
            if(monitorPointType.equals("测试桩"))
            {
                EQPTBaseService service= SpringAppliction.getBean(EQPTBaseService.class);
                EqptCptestStation device=service.queryObjectByCustomNumber(EqptCptestStation.class,val);
                if(device == null)
                {
                    return false;
                }
                try
                {

                    BeanUtils.setProperty(c,"mileage",""+device.getMileage());

                }catch (Exception e3)
                {

                }
                CpTestStationExpandService cpTestStationExpandService = SpringAppliction.getBean(CpTestStationExpandService.class);
                EqptCppowerr eqptCppowerr = cpTestStationExpandService.queryPower(device.getId());
                if(eqptCppowerr != null)
                {
                    BeanUtils.setProperty(c,f.getName(),device.getId());

                    return true;
                }else{
                    return false;
                }


            }else if(monitorPointType.equals("露管")){


            }else if(monitorPointType.equals("缺陷点")){
                //TODO 我不知道哪个是缺陷点的的表，所以 写不出来。。。。

            }
            BeanUtils.setProperty(c,f.getName(),null);


        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } catch (InvocationTargetException e1) {
            e1.printStackTrace();
        } catch (NoSuchMethodException e1) {
            e1.printStackTrace();
        }
        return true;
    }

    @Override
    public String getName() {
        return null;
    }
}

